﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geometry;

namespace ComponentGIS.Tool
{
    class MapZoomOutTool : ICommand, ITool
    {
        #region 字段
        private IHookHelper hookHelper;
        private IMapControl2 mapControl;
        #endregion

        #region ITool成员
        public int Cursor
        {
            get
            {
                ISystemMouseCursor pMouse = new SystemMouseCursorClass();
                pMouse.Load(esriSystemMouseCursor.esriSystemMouseCursorZoomOut);
                return pMouse.Cursor;
            }
        }

        public bool Deactivate()
        {
            return true;
        }

        public bool OnContextMenu(int x, int y)
        {
            return false;
        }

        public void OnDblClick()
        {
        }

        public void OnKeyDown(int keyCode, int shift)
        {
        }

        public void OnKeyUp(int keyCode, int shift)
        {
        }

        public void OnMouseDown(int button, int shift, int x, int y)
        {
            if (button == 2) return;
            //框选
            IEnvelope pEnvExtent = mapControl.Extent;
            IEnvelope pEnvRECT = mapControl.TrackRectangle();
            //点选
            if (pEnvRECT.IsEmpty || pEnvRECT.Width == 0 || pEnvRECT.Height == 0)
                pEnvExtent.Expand(1.5, 1.5, true);
            else
                pEnvExtent.Expand(pEnvExtent.Width / pEnvRECT.Width,
                    pEnvExtent.Height / pEnvRECT.Height, true);
            mapControl.Extent = pEnvExtent;
            mapControl.Refresh();
        }

        public void OnMouseMove(int button, int shift, int x, int y)
        {
        }

        public void OnMouseUp(int button, int shift, int x, int y)
        {
        }

        public void Refresh(int hdc)
        {
        }
        #endregion

        #region ICommand成员
        public int Bitmap
        {
            get { return -1; }
        }

        public string Caption
        {
            get { return "地图缩小"; }
        }

        public string Category
        {
            get { return "地图浏览"; }
        }

        public bool Checked
        {
            get { return false; }
        }

        public bool Enabled
        {
            get { return true; }
        }

        public int HelpContextID
        {
            get { return -1; }
        }

        public string HelpFile
        {
            get { return string.Empty; }
        }

        public string Message
        {
            get { return "地图缩小"; }
        }

        public string Name
        {
            get { return "MapZoomOutTool"; }
        }

        public void OnClick()
        {
        }

        public void OnCreate(object Hook)
        {
            hookHelper = new HookHelperClass();
            hookHelper.Hook = Hook;
            mapControl = Hook as IMapControl2;
            if (hookHelper.ActiveView == null)
                hookHelper = null;
        }

        public string Tooltip
        {
            get { return "地图缩小"; }
        }
        #endregion
    }
}
